﻿#define _CRT_SECURE_NO_WARNINGS 1

//编程初学者入门训练第九十四题
//BC96 有序序列判断
//https://www.nowcoder.com/practice/22e87f8a8d764a6582710f38d1b40c6e?tpId=107&tqId=33377&rp=1&ru=/exam/oj/ta&qru=/exam/oj/ta&sourceUrl=%2Fexam%2Foj%2Fta%3FtpId%3D107&difficulty=undefined&judgeStatus=undefined&tags=&title=

#include <stdio.h>

int main() {
    int n = 0;
    int arr[50] = { 0 };
    scanf("%d", &n);
    //输入数据
    for (int i = 0; i < n; i++) {
        scanf("%d", &arr[i]);
    }

    int flag = 1;//升序序列标识
    int flag1 = 1;//降序序列标识
    //判断升序
    for (int i = 0; i < n - 1; i++) {
        if (arr[i] > arr[i + 1]) {
            flag = 0;
            break;
        }
    }

    //判断降序
    for (int i = 0; i < n - 1; i++) {
        if (arr[i] < arr[i + 1]) {
            flag1 = 0;
            break;
        }
    }

    //如果flag都为0则unsorted
    if (flag == 0 && flag1 == 0)
        printf("unsorted\n");
    else if (flag || flag1)
        printf("sorted\n");

    return 0;
}

//思路2：如果能只判断有序即可，不必在意升序还是降序
#include<stdio.h>

int main()
{
    int i, arr[100], n, cnt1 = 0, cnt2 = 0;
    scanf("%d", &n);
    for (i = 0; i < n; i++)
    {
        scanf("%d", &arr[i]);
    }

    for (i = 0; i < n - 1; i++)
    {
        if (arr[i] - arr[i + 1] >= 0)
            cnt1++;//降序计数
        else if (arr[i] - arr[i + 1] <= 0)
            cnt2++;//升序计数
    }

    if (cnt1 == n - 1 || cnt2 == n - 1)//一共n个数，两两相减的到n-1个结果
        printf("sorted");
    else
        printf("unsorted");
}
